<template>
  <div>
    <el-table v-loading="loading" :data="dataSource" @row-click="handleRowClick" :height="autoHeight" @row-contextmenu="rightClick">
<!--      <el-table-column type="expand" align="center" label="数据列" width="80px">
        <column-table slot-scope="scope" :lab-db="labDb" :jdbc-table="scope.row" @rowSelect="(row) => {$emit('columnSelect',row)}" :select="select" style="padding: 0 12px"/>
      </el-table-column>-->
      <el-table-column prop="jdbcName" label="表名" align="center" show-overflow-tooltip>
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
<!--      <el-table-column prop="jdbcComment" label="表备注" align="center" show-overflow-tooltip>
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>-->
      <el-table-column v-if="select" align="center" label="操作" width="65px">
        <template slot="header" slot-scope="scope">
          <el-button v-if="scope && !select" type="primary" @click="addTable" icon="el-icon-circle-plus-outline"></el-button>
          <div v-else>操作</div>
        </template>
        <template slot-scope="scope">
          <template v-if="select">
            <el-button type="success" icon="el-icon-thumb" circle @click="$emit('rowSelect',scope.row)" title="选择"></el-button>
          </template>
          <template v-else>
            <el-button type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[20, 50, 100, 200, 500]"
            :page-size="pageInfo.pageSize"
            layout="total"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "TableTable",
  components: {
    ColumnTable: () => import('@/views/system/db/ColumnTable')
  },
  mixins: [IdeaTable],
  props: {
    labDb: {
      type: Object,
      default: function () {
        return {}
      }
    },
    select: {
      type: Boolean,
      default: false
    }
  },
  computed:{
    autoHeight() {
      return `calc(100vh - 185px)`
    }
  },
  mounted() {
    this.initSchema()
  },
  methods: {
    initSchema(){
      this.queryUrl = `db/tables/${this.labDb.dbId}`
      this.removeUrl = `db/removeTable/${this.labDb.dbId}/`
      this.rowKey = 'jdbcName'
      this.pageInfo.pageSize = 500
      this.rightButtons.splice(0, this.rightButtons.length)
      this.appendRightBtn({ label: '新增', icon: 'el-icon-circle-plus-outline', click: this.addTable })
      this.appendRightBtn({ label: '删除', icon: 'el-icon-delete', click: this.removeData })
      this.loadSource()
    },
    addTable() {
      this.$emit('rowSelect',{ addFlag: true, jdbcName: 'xxx_yyy_zzz' })
    }
  }
}
</script>

<style scoped>

</style>
